<template>
	<div>
		<!--flag为true表示常规商品    flag 为false为大件商品-->
        <confirm-order-address></confirm-order-address>     
		<confirm-send-methods></confirm-send-methods>									<!--idName="name1" :flag= true-->
		<confirm-getTime ref="nomalTimeshow" :data1 = "normalTime" :data2 = "bigTime" :checkedCartListNormal="checkedCartListNormal" :checkedCartListBig="checkedCartListBig"  :money="bigNormalM" :hasBigFlag="checkedCartListBig.length > 0?true:false" ></confirm-getTime>
		<confirm-order-list :checkedCartList="checkedCartList" :checkedCartListNormal="checkedCartListNormal" :checkedCartListBig="checkedCartListBig" :flag= true :delFlag="delFlag"></confirm-order-list>
        <div style="width: 100%;height: 4rem;" v-if="checkedCartList.length < 0"></div>
		<!--<confirm-send-methods v-if="checkedCartListBig.length > 0"></confirm-send-methods>-->
		<!--<confirm-getTime :data1 = "bigTime" :money="bigM" idName="name2" :flag= false v-if="checkedCartListBig.length > 0"></confirm-getTime>
		<confirm-order-list :checkedCartList="checkedCartListBig" :flag= false :delFlag="delFlag" v-if="checkedCartListBig.length > 0"></confirm-order-list>-->

		<confim-order-send-gift v-if="getGiftSendArr.length > 0"></confim-order-send-gift>
							<!--supportInvoiceFlag 隐藏发票入口-->
		<confirm-order-fp v-if="false" :toFp="toFp"></confirm-order-fp>
		<confirm-order-detail @sendGoodsList="cartList" :sendOrder="checkStoreRange" @sendWithoutMoney="getMoneyWithoutCode" @changeTotalMoney="getTotalMoney" :checkedCartList="checkedCartList" :normalList="checkedCartListNormal" :bigList="checkedCartListBig" :sendMoney="sendMoney"></confirm-order-detail>
		<!--<confirm-coupons></confirm-coupons>-->
		<div id="stores_map" style="width: 0;height: 0;"></div>
		<!--<confirm-order-pursekey  ref="pursekey" :sendOrder="sendOrder"></confirm-order-pursekey>-->
	</div>
</template>

<script>
	import {Toast} from '../../../utils/toast';
	import axios from 'axios';
	import ConfirmGetTime from "../../../real-components/ConfirmOrder/ConfirmGetTime";
	import ConfirmOrderList from "../../../real-components/ConfirmOrder/ConfirmOrderList";
	import ConfirmOrderDetail from "../../../real-components/ConfirmOrder/ConfirmOrderDetail";
	import ConfirmSendMethods from "../../../real-components/ConfirmOrder/ConfirmSendMethods";
	import ConfirmOrderFp from "../../../real-components/ConfirmOrder/ConfirmOrderFp";
	import ConfirmOrderPursekey from "../../../real-components/ConfirmOrder/ConfirmOrderPursekey";
	import ConfimOrderSendGift from "../../../real-components/ConfirmOrder/ConfimOrderSendGift";
	import {mapGetters,mapActions,mapMutations} from "vuex";
	import {normal} from "../../../config/orderTypeCode";
    import {MessageBox} from '../../../ui-components';
    import ConfirmOrderAddress from "../ConfirmOrderAddress";

	export default {
		props: {
            
        },
        computed:{
        	...mapGetters('wxh',[
				'sessionId',
				'userInfo'
			]),
			...mapGetters('qxz',[
        		"getLocation"
        	]),
			...mapGetters('zx',[
				'getAddressDetail','getMynode',"getTimeNormal","getTimeBig","getNormalM","getBigM",
				"getDeliveryType","getFpObj","getTicketList","getLadderIdList","getGiftVOList",
				"getStoreNow","getUseGiftCard","getAvailAmount","getGiftSendArr","getToken","getOrderFlag","getTimeSaveObj"
			]),
			...mapGetters([
        		"getConfigParams"
        	]),
			normalTime(){
				return this.normalTimeList;
			},
			bigTime(){
				return this.bigTimeList
			},
			normalM() {
				if (this.getNormalM) {
					return this.getNormalM.normalM;
				}
			},
			bigM(){
				if (this.getBigM) {
					return this.getBigM.bigM;
				}
			},
			bigNormalM(){
//				if (this.getNormalM && !this.getBigM) {
//					return this.getNormalM.normalM;
//				}else if (this.getBigM && !this.getNormalM) {
//					return this.getBigM.bigM;
//				}else{
//					return this.getNormalM.normalM + this.getBigM.bigM;
//				}
			}
        },
        data () {
        	// distributiontype 0 表示常规商品  1 表示大件商品
            return {
                checkedCartList:[],   //购物车所有商品
                checkedCartListNormal:[],   //用于存放常规商品的数组
                checkedCartListBig:[],  //用于存放大件商品的数组
                maxTimeNormal:[],   //用于请求时间列表接口的参数
                maxTimeBig:[],    //用于请求时间列表接口的参数
                normalTimeList:[], //用于接收常规商品时间列表请求结果
                bigTimeList:[],   //用于接收大件商品时间列表请求结果
                shopCartIds:[],      //用于下单的参数
                address:null,
                sendMoney:[],
                supportInvoiceFlag:false,
                myMap:null, // 地图对象
                storeRange:null,  // 配送范围
            	moneyWithoutC:0 , //钱包免密金额
            	totalMoney:0,  // 应付金额
            	keyall:null , // 钱包密码
            	showMask:false, //是否需要用戶輸入密碼
            	delFlag:0,   // 用于修改样式
            	clickFlag:true,  // 防止两次快速点击 调用两次下单接口
            	showTimeFlag:false  // 控制选择常规时间的弹出框是否显示
            }
        },
        watch:{
        	getToken(newVal,oldVal){
        		console.log(newVal);
        	}
        },
        methods: {
        	...mapMutations('cjy',[
        		"changeCheckedCartList"
        	]),
        	...mapMutations('zx',[
        		"setTimeNormal","setTimeBig","setFpObj","setShowMask","setUseGiftCard","setaddFlagMutation","setNowAddressMutation","setToken","setOrderFlag","setFpInfo"
        	]),
        	//让最后一个商品列表没有margin-bottom  判断是只有常规  只有大件 既有常规又有大件
//      	delMarginFlag(){
//      		if(this.checkedCartListNormal.length > 0 && this.checkedCartListBig.length = 0){
////      			只有常规
//					this.delFlag = 1;
//      		}else if(this.checkedCartListNormal.length = 0 && this.checkedCartListBig.length > 0){
//      			//只有大件
//      			this.delFlag = 2;
//      		}else if(this.checkedCartListNormal.length > 0 && this.checkedCartListBig.length > 0){
//      			//既有常规又有大件
//      			this.delFlag = 3;
//      		}
//      	},
        	//获取最大时间
        	getMaxTime(arr){
        		console.log(arr,"常规 大件”");
        		if(arr.length > 0){
        			var max1 = arr[0].distributionpreparationtime;
	        		var max2 = arr[0].distributionprocessingtime;
	        		var myArr = [];
	        		for(let i = 0; i < arr.length; i++){
	        			if(max1 < arr[i].distributionpreparationtime){
	        				max1 = arr[i].distributionpreparationtime;
	        			}
	        			if(max2 < arr[i].distributionprocessingtime){
	        				max2 = arr[i].distributionprocessingtime;
	        			}
	        		}
	        		myArr.push(max1);
	        		myArr.push(max2);

	        		return myArr;
        		}
        	},
        	//获取初始数据
        	cartList(){
        		//获取所有购物车商品
        		this.checkedCartList = this.$store.state.cjy.checkedCartList;

        		//区分大件商品和常规商品  0 常规   1 大件
				for(var i = 0; i < this.checkedCartList.length; i++){
					var obj = {}
					obj['rid'] = this.checkedCartList[i].rid;
					this.shopCartIds.push(obj);
					console.log(this.checkedCartList[i],this.checkedCartList[i].rid,'商品唯一标志')
					if(this.checkedCartList[i].distributiontype === 0 || this.checkedCartList[i].distributiontype === null){
						this.checkedCartListNormal.push(this.checkedCartList[i]);
					}else if(this.checkedCartList[i].distributiontype === 1){
						this.checkedCartListBig.push(this.checkedCartList[i]);
					}
				}


				//获取到常规和大件的加工时间 准备时间
				this.maxTimeNormal = this.getMaxTime(this.checkedCartList);
				this.maxTimeBig = this.getMaxTime(this.checkedCartListBig);


//				if(this.checkedCartListNormal.length > 0){
//					this.getTimeList(this.maxTimeNormal,0);
//				}
//				if(this.checkedCartListBig.length > 0){
//					this.getTimeList(this.maxTimeBig,1);
//				}


				var obj = this.getTimeSaveObj;
				let flag = this.checkObj(obj);
        		if(!flag){
        			this.getTimeUserChoose();
        		}else{
        			//请求昌松的可选时间接口   获取时间列表
					if(this.checkedCartListNormal.length > 0){
						this.getTimeList(this.maxTimeNormal,0);
					}
					if(this.checkedCartListBig.length > 0){
						this.getTimeList(this.maxTimeBig,1);
					}
        		}


        	},
        	//判断对象是否为空的方法
			checkObj(obj) {
				for(var key in obj) {
					return false;
				}
				return true;
			},
        	//从vue中 获取用户已经选择了的配送时间数据
        	getTimeUserChoose(){
        		var obj = this.getTimeSaveObj;
    			this.normalTimeList = obj.data1;
				//大件的配送时间
				this.bigTimeList = obj.data2;
//				this.money =  obj.money;
				console.log(this.normalTimeList,this.bigTimeList,'大件商品常规商品哈哈哈哈哈哈哈')
        	},
        	//获取用户收货地址
        	getToPayAddress(){
//      		var myAddress = JSON.parse(localStorage.getItem('locationAdd'));
        		var myAddress = this.getLocation;
				let arr = this.userInfo.addressLists;
				console.log(this.$route.query)
				var query = null;
				if(this.$route.query && this.$route.query.name){
					 query = JSON.parse(this.$route.query.name);
				}
//				console.log(query,'55588855588555query');
				if(query && query.flag){
					this.address = query;
					return true;
				}else if(myAddress && myAddress.addressid == -1){
					var address = {
						address:myAddress.address,
						city:myAddress.city,
						defaultaddress:"1",
						label:"0",
						phone:"",
						positionlat:myAddress.positionlat,
						positionlng:myAddress.positionlng,
						province:myAddress.province,
						receivername:"",
						region:myAddress.region,
						result:"",
						sex:"0",
						houseNumber:''
					}
					this.setaddFlagMutation(true);
					this.setNowAddressMutation(address);

					//存local 防止vuex失效  当失效时取用
					localStorage.setItem('userAddressNow',JSON.stringify(address));

					this.$router.push({ path: 'addAddress',query:{id:1,obj:JSON.stringify(address)}});
					return false;

				}else if(myAddress && myAddress.addressid != -1){
					this.address = myAddress;
					return true;
				}else{
					return true;
				}
        	},


        	//获取时间列表方法
        	getTimeList(data,type){
        		console.log(data,type)
        		let params = {
        			readyTm:data[0],
        			machineTm:data[1],
					storeCode:localStorage.getItem('storeCode')
        		};


        		let config = {
//	            	url:window.api.local_host+"/delivery_config/tm_interval/"+type,
//	            	url:'http://172.19.6.152:33003'+"/delivery_config/tm_interval/"+type,
					url:window.api.trade_host+"/delivery_config/tm_interval/"+type,
	            	method: 'GET',
	            	params,
	            	headers: {'sessionId': this.sessionId},
	           };
	           console.log(config.url)
	           axios(config).then((res)=>{
	           		console.log(res.data.data,'shiajianliebaios',type);
	           		if(type === 0){
	           			if(res.data.data && res.data.data.length){
	           				this.normalTimeList = res.data.data;
	         				console.log(res.data.data,'时间')
		           			//初始化store中的时间
		           			for(let i = 0; i < res.data.data[0].deliveryList.length;i++){
		           				if(res.data.data[0].deliveryList[i].valid == 1){
		           					this.setTimeNormal(res.data.data[0].deliveryList[i]);
		           					return
		           				}
		           			}
	           			}

	           		}else if(type === 1){

	           			this.bigTimeList = res.data.data;
//	           			console.log(res.data.data,'获取到jieguo');
	           			//初始化store中的时间
	           			if(res.data.data[0]){
		           			for(let i = 0; i < res.data.data[0].deliveryList.length;i++){
		           				if(res.data.data[0].deliveryList[i].valid == 1){
		           					this.setTimeBig(res.data.data[0].deliveryList[i]);
		           					return
		           				}
		           			}
	           			}
//	           			console.log(res.data.data,'获取到了big')
//	           			console.log(this.bigTimeList,'获取到了big')
	           		}
	           })
        	},
        	//获取起送额
        	getmoneySend(){
        		let config = {
					url:window.api.trade_host+"/delivery_config/delivery/"+localStorage.getItem('storeCode'),
	            	method: 'GET',
	            	headers: {'sessionId': this.sessionId},
	            };
	             axios(config).then((res)=>{
//	             	console.log(res.data.data[0],'获取汽配额度');
	             	this.sendMoney = res.data.data[0];

	             })
        	},
        	//判断是否展示发票入口
        	supportInvoice(){
        		this.supportInvoiceFlag = this.getConfigParams.supportInvoice;
        	},
        	innitFpData(){
				let url = window.api.service_host + '/mallconfig/selectInvoice';
				let config = {
					url: url,
					method: 'GET',
					headers: {
						'sessionId': this.sessionId
					},
				};

				axios(config).then((res)=>{
					var str = ''; // 用于存放发票内容
					if(res.data.returnCode === 1){
						var fpInfo = res.data.data[0];
						this.supportInvoiceFlag = res.data.data[0].supportInvoice;
						this.setFpInfo(fpInfo);
					}
				})
			},
        	// 去发票页面
        	toFp(){
        		this.$router.push("orderfpInfo")
        	},
        	//获取优惠券参数
        	getCouponParams(){
        		var newArr = [];
        		let arr = this.getTicketList;
        		for(let i = 0 ; i < arr.length; i++){
//      			console.log(newArr)
//      			let obj = {};
//      			obj.voucherType = arr[i].couponType;
//      			obj.voucherName = arr[i].couponName;
//      			obj.voucherCode = arr[i].qrCode;
//      			obj.voucherId = arr[i].couponId;
        			newArr.push(arr[i].qrCode);
        		}
//      		console.log(newArr,'实用的游湖uiquan')
        		return newArr;
        	},
//      	获取订单返利参数
			getLadderParams(){
				return this.getLadderIdList;
			},
			//获取满赠参数
			getGiftParams(){
				return this.getGiftVOList;
			},
        	//获取发票参数
        	getFpParams(){
        		var newObj = {};
        		let obj = this.getFpObj;
        		if(!obj){
        			return;
        		}
        		if(obj.invoiceTitle == "单位"){
        			newObj.invoiceType = obj.invoiceTypeCode;  //类型
	        		newObj.invoiceHead = obj.invoiceTitle ; // 抬头
					newObj.taxpayerNo = obj.taxpayerNo ;// 税号
					newObj.companyName = obj.companyName; // 公司名字
					newObj.invoiceContent  = obj.content ;  //发票内容
        		}else if(obj.invoiceTitle == "个人"){
					newObj.invoiceType = obj.invoiceTypeCode;  //类型
	        		newObj.invoiceHead = obj.invoiceTitle ; // 抬头
	        		newObj.invoiceContent  = obj.content;   //发票内容
				}

				return newObj;
        	},
        	//获取 门店配送范围
        	getRange(){
        		var storeNow = this.getStoreNow;
        		console.log(storeNow,'当前门店');
				var range1 = storeNow.deliveryRangeCode.match(/\d+/g);
				var range2 = storeNow.deliveryRangeName.match(/\d+/g);
				if(range1 != null){
					this.storeRange = Number(range1[0]) * 1000;
				}else if(range2 != null){
					this.storeRange = Number(range2[0]) * 1000;
				}
			},
        	//是否使用钱包支付
        	checkBuyByCard(){
        		var flag = this.getUseGiftCard;
//      		console.log(flag);
        		return flag;
        	},
        	//获取免密金额
        	getMoneyWithoutCode(data){
        		if(data != null){
        			this.moneyWithoutC = data;
        		}
//      		console.log(this.moneyWithoutC,data,'aLog');
        	},
        	//获取应付金额
        	getTotalMoney(money){
//      		console.log(money,'钱钱')
        		this.totalMoney = money;
        	},
        	//判断是否需要填密码
        	checkPurse(){

        		let flag = this.checkBuyByCard();
        		if(flag){
        			var balanceM = Number(this.getAvailAmount);  // 钱包可用余额
	        		var moneyWithoutC = Number(this.moneyWithoutC);   // 钱包免密金额
	        		var totalMoney = Number(this.totalMoney);  // 订单应付金额
					console.log(moneyWithoutC,totalMoney,balanceM,'en ')
	        		if(moneyWithoutC == null || moneyWithoutC == 0){
	        			console.log('用户没有设置免密金额，需要验证密码')
	        			this.$refs.pursekey.showOrHide();
						this.$refs.pursekey.clearKeyall();
	        			return
	        		}
	        		//1 钱包支付金额是否 大于最大免密金额   (可用余额)
	        		if(balanceM >= totalMoney){
	        			//使用 应付金额 判断是否填写密码  订单完成 不用去支付页
	        			if(totalMoney > moneyWithoutC){
	      				 //填密码
//	      				 	this.showMask = true;
							console.log(11111)
	      				 	this.$refs.pursekey.showOrHide();
							this.$refs.pursekey.clearKeyall();
//	      				 	this.setShowMask(true);
	        			}else{
	        			 //不填密码
	        				console.log('不用输入密码1')	;
	        				this.sendOrder();
	        			}

	        		}else{

	        			if(balanceM > moneyWithoutC){
	      				 //填密码
	      				    this.$refs.pursekey.showOrHide();
							this.$refs.pursekey.clearKeyall();
	        			}else{
	        			 //不填密码
	        				console.log('不用输入密码2');
							this.sendOrder();
	        			}
	        		}
        		}else{
        			this.sendOrder();
        		}
        	},
        	//将提交订单的地址  isNew置为 0
        	setAddressIsNew(item){
        		let params = {
					type:"UPDATE",
					userid: item.userid,
					addressid:item.addressid,
					enterprisecode:window.api.enterpriseCode
				}
				var sessionId = localStorage.getItem('sessionId');
				let config = {
					url: window.api.customer_host+'/address',
					method:'POST',
					data:params,
					headers: {'sessionId': sessionId, 'Content-Type':'application/json', 'Accept' : 'application/json'},
				}
				axios(config).then((res)=>{
					console.log(res);
				})
        	},
        	//弹出选择配送时间让用户确认，用户不点击确定就一直弹出 选择时间的弹出框
        	makeSureTime(){
        		let flag = this.$refs.nomalTimeshow.chooseFlag;
        		let flagXiaDan = false;
//      		console.log()
        		if(!flag){
        			this.$refs.nomalTimeshow.showPop();
        		}else{
        			flagXiaDan = true;
        		}
				return flagXiaDan;
        	},
        	//校验门店是否在配送范围内
        	checkStoreRange(){

        		var that = this;
        		var myTimer = setTimeout(function(){
//      			console.log('定时器')
        			that.clickFlag = true;
        		},5000)

        		let payAddressFlag = this.getToPayAddress();  //获取用户收货地址

        		if(!payAddressFlag){
        			return;
        		}

  				if(!this.sessionId){
  					this.$router.push('login');
  				}
  				if(!this.address || !this.address.addressid || this.address.addressid==-1){
  					Toast({
		                message: '请选择收货地址',
		                duration: 1000,
		                type:'fail'
		            });
		            return
  				}

        		let flagXiaDan = this.makeSureTime();
				if(!flagXiaDan){
					return
				}

				console.log(this.clickFlag,'防止多次点击')
        		//防止多次点击下单
        		if(!this.clickFlag){
        			return ;
        		}


        		this.clickFlag = false;  // 点击后置为禁用状态
        		var url = window.api.customer_host + "/address/getTMS";
        		var params = {
        			longitudeandlatitude:this.address.positionlng + ',' + this.address.positionlat
        		}
        		var config = {
        			url:url,
        			method:"GET",
        			params
        		}
        		axios(config).then((res)=>{
        			console.log(res.data.returnCode,'校验配送地址');
        			if(res.data.returnCode == 0){
        				Toast({
			                message: '该地址不在配送范围内',
			                duration: 1000,
			                type:'fail'
			            });

			            this.clickFlag = true;  //接口返回  解除点击禁用

        			}else if(res.data.returnCode == 1){
        				//如果地址存在  将该地址推送到首页和选择地址页
	  					console.log(res.data.data[0],'88888');
	  					this.setAddressIsNew(this.address);
	  					localStorage.setItem('locateIn',JSON.stringify(this.address));
						this.$store.dispatch('qxz/updateLocation', this.address);
						var latticeName = res.data.data[0].latticename;
						this.sendOrder(latticeName);
        			}
        		})
        	},
        	//生成订单
        	async sendOrder(latticeName){

//				console.log(this.getOrderFlag,'打印信息误删')
        		// 判断获取金额信息接口是否已返回数据  没返回就禁止下单
        		console.log('进来')
        		if(!this.getOrderFlag){
        			return;
        		}
				console.log('进来')
        		//防止多次点击下单
//      		if(!this.clickFlag){
//      			return ;
//      		}
//
//      		this.clickFlag = false;  // 点击后置为禁用状态
//
//
//      		let payAddressFlag = this.getToPayAddress();  //获取用户收货地址
//
//      		if(!payAddressFlag){
//      			return;
//      		}
//
//				if(!this.sessionId){
//					this.$router.push('login');
//				}
//				if(!this.address || !this.address.addressid || this.address.addressid==-1){
//					Toast({
//		                message: '请选择收货地址',
//		                duration: 1000,
//		                type:'fail'
//		            });
//		            return
//				}else{
//  				this.checkStoreRange();
//					//如果地址存在  将该地址推送到首页和选择地址页
//					console.log(this.address,'88888');
//					this.setAddressIsNew(this.address);
//					localStorage.setItem('locateIn',JSON.stringify(this.address));
//					this.$store.dispatch('qxz/updateLocation', this.address);
//				}

//  			console.log(this.address,'收货地址信息');
  				var orderDeliveryTms  = [];
  				var norObj = {};
  				var bigObj = {};
  				var norMalTime = this.getTimeNormal;
  				var bigTime = this.getTimeBig;
//				console.log(norMalTime,'去下单罗');
				if(norMalTime){
					norObj.expectedTmStart = norMalTime.startPeriodTm;
					norObj.expectedTmEnd = norMalTime.endPeriodTm;
					norObj.showStartTm = norMalTime.startBookTm;
					norObj.showEndTm = norMalTime.endBookTm;
					norObj.goodsDeliveryType = 0;
				}

				if(bigTime){
					bigObj.expectedTmStart = bigTime.startPeriodTm;
					bigObj.expectedTmEnd = bigTime.endPeriodTm;
					bigObj.showStartTm = bigTime.startBookTm;
					bigObj.showEndTm = bigTime.endBookTm;
					bigObj.goodsDeliveryType = 1;
				}

//				console.log(norMalTime,bigTime,'8888')
				if(this.checkedCartListNormal.length != 0){
//					console.log('怎么进来的')
					orderDeliveryTms.push(norObj);
				}
				if(this.checkedCartListBig.length != 0){
					orderDeliveryTms.push(bigObj);
				}
//				console.log(this.checkedCartListNormal,this.normalTimeList[0].deliveryList.length);
				console.log('收货地址信息');
				if(this.normalTimeList){

					if(this.checkedCartListNormal.length > 0){
						console.log(123)
						if( this.normalTimeList.length == 0 || this.normalTimeList[0].deliveryList.length == 0){
							Toast({
				                message: '暂无可配送时间',
				                duration: 1000,
				                type:'fail'
				            });
				            return
						}

					}
				}

				if(this.bigTimeList){
					console.log('下单++++++++++++++++++++++++++++++++++==',this.bigTimeList)
					if(this.checkedCartListBig.length > 0){

						if(this.bigTimeList.length == 0 || this.bigTimeList[0].deliveryList.length == 0){
							Toast({
				                message: '暂无可配送时间',
				                duration: 1000,
				                type:'fail'
				            });
				            return
						}
						console.log('暂无可配送时间')
					}
				}
				//获取对象的length
				if(!Object.getOwnPropertyNames(orderDeliveryTms[0]).length){

					Toast({
		                message: '请选择配送时间',
		                duration: 1000,
		                type:'fail'
		            });
		            return
				}
				//校验配送方式
				if(!this.getDeliveryType){
					Toast({
		                message: '未获取到配送方式',
		                duration: 1000,
		                type:'fail'
		            });
		            return
				}
        		let params = {
        			addressId:this.address.addressid,
        			cartId:this.checkedCartList[0].cartId,
//      			logisticsType:0,
					deliveryType:this.getDeliveryType,  //配送方式
        			note:this.getMynode,
        			shopCartIds:this.shopCartIds,
					storeCode:localStorage.getItem('storeId'), //调试用的 '5555555'  localStorage.getItem('storeId')   3df87595-762d-414e-be0f-6b6d8361f5d2  73ece0ae-ba0e-4501-b993-d727b9ae25c2
        			orderDeliveryTms,
        			latticeName:latticeName // wms网格  测试需要传该参数   预发布和生产不能传该参数
        		};

        		console.log(params,'下单时的入参');
				// console.log(this.$route.path,window.location,'路由链接')
				// return
//      		let locationHost = window.location.hostname.split(':');
//				if(locationHost[0] === 'test'){
//					params.latticeName = latticeName;  // wms网格  测试需要传该参数   预发布和生产不能传该参数
//				}

        		let flag = this.checkBuyByCard();//入参 walletPayed 0 代表常规支付   1代表钱包支付
        		if(flag){
        			params.walletPayed = 1;
        		}else{
        			params.walletPayed = 0;
        		}


        		var couponParams = this.getCouponParams();  // 获取优惠券参数
        		if(couponParams && couponParams.length != 0){
        			params.qrCodeList = couponParams;
        		}

        		var ladderIdList = this.getLadderParams(); // 获取阶梯返利满赠参数
        		if(ladderIdList && ladderIdList.length != 0){
        			params.ladderIdList = ladderIdList;
        		}

        		var giftVOList = this.getGiftParams();
        		if(giftVOList && giftVOList.length != 0){
        			params.giftVOList = giftVOList;
        		}


				if(Object.keys(this.getFpObj).length){
        			var fpParams = this.getFpParams();  // 获取发票参数
        		}

        		if(fpParams){
        			params.orderInvoice = fpParams;
        		}

        		let query = this.$route.query.name;


        		params.deliveryAddress = this.getAddressDetail;

        		params.token  = this.getToken;  // 传token用于后台识别

        		let config = {
	            	url: window.api.trade_host+'/order/insertDto',
	            	method: 'POST',
	            	data: params,
	            	headers: {'sessionId': this.sessionId, 'Content-Type':'application/json', 'Accept' : 'application/json'},
	            }

//      		return;


        		if(this.address && orderDeliveryTms.length > 0){
//      			console.log(params,'下单请求参数信息')
	        		try{
	        			let data = await axios(config);
//	        			axios(config).then((data)=>{
        				console.log(params,'下单请求参数信息')
        				this.clickFlag = true;  //接口返回  解除点击禁用
						console.log(data,'返回参数')
	        			if(data.data.returnCode == 1 ){

	        				console.log(this.totalMoney,'订单生成');

	        				var arr = [];
	        				this.changeCheckedCartList(arr);
	        				this.$store.dispatch('cjy/queryCart');

							var orderNo = data.data.data[0];
							if(this.totalMoney != 0){
								this.$router.push({name: "pay", params: {orderNo:orderNo,orderType:normal}});
							}else{
								this.$router.push({name: "paysuccessfully", params: {orderType:normal}});
							}
	        			}else{
	        				var token = data.data.data[0];
	        				this.setToken(token);  //下单失败 后台重新返回 token 用于再次下单
	        				MessageBox.confirm('您的商品信息已失效，请重新下单').then((action)=>{
				            	this.$router.push('cart');
				            })
//		        				Toast({
//					                message: data.data.msg,
//					                duration: 1000,
//					                type:'fail'
//					            });
	        			}
//		        		})
	        		}catch(err) {
						console.log(err,'错误信息')
	        			this.clickFlag = true;  //接口返回  解除点击禁用
						Toast({
							message: '生成订单失败',
							duration: 1000,
							type: 'fail'
						});
					}
        		}
        	}
        },
        components: {
	        "confirm-order-detail": ConfirmOrderDetail,
	        "confirm-getTime": ConfirmGetTime,
	        "confirm-order-list": ConfirmOrderList,
	        "confirm-send-methods":ConfirmSendMethods,
	        "confirm-order-fp":ConfirmOrderFp,
	        "confirm-order-pursekey":ConfirmOrderPursekey,
            "confim-order-send-gift":ConfimOrderSendGift,
            "confirm-order-address":ConfirmOrderAddress,
	    },
	    beforeDestroy(){
	    	this.clickFlag = true; //接口返回  解除点击禁用
	    	this.setOrderFlag(false); // 将提交按钮设置为禁用状态
//	    	this.setFpObj({});   // 重置发票对象的在indexvue中实现
	    },
	    mounted(){
//	    	console.log(normal,'*****//////******//////')

	    },
	    created(){
	    	// this.cartList();
	    	this.getmoneySend();
//	    	this.innitFpData(); // 获取发票信息	 需求暂时不获取发票信息
	    }
	}
</script>

<style>
    .chooseBoxCofirm {
        flex-direction: column;
        display: flex;
        width:345;
        min-height:102;
        justify-content:flex-start;
        align-items:center;
        background:#fff;
        border-radius:5;
    }
    .addressChooseStyle {
        width:90%;
        min-height: 63;
        justify-content: 'center';
        align-items: 'center';
        border-bottom: 1px;
        border-bottom-color: #e8e8e8;
    }
    .timeChooseStyle {
        width:90%
    }

</style>
